<script setup lang="ts">
  import { HMessage, HMessageBox } from '@/components/common/message'
  import { useCheckQuote } from '@/services/pages/order/useQuote'

  const { checkForm, checkLoading, check, resetCheckForm } = useCheckQuote()

  defineOptions({
    name: 'OrderCheckQuoteModal',
  })

  const props = defineProps({
    orderId: {
      type: String,
      required: true,
    },
  })

  const emits = defineEmits<{
    (e: 'update'): void
  }>()

  // 弹窗显示状态
  const visible = defineModel('modelValue', { type: Boolean, default: false })

  /**
   * 隐藏弹窗
   */
  const hideDialog = () => {
    visible.value = false
    resetCheckForm()
  }

  /**
   * 确定事件
   */
  const onConfirm = async () => {
    const res = await check(props.orderId)
    if (res.code === 20000) {
      HMessage.success('审核完成')
      hideDialog()
      emits('update')
      return
    }

    HMessageBox.error(res.message)
  }
</script>

<template>
  <h-dialog v-model="visible" title="审核报价" :loading="checkLoading" @close="hideDialog">
    <el-form :model="checkForm" class="modal_form_content">
      <!--审核结果-->
      <el-form-item label="审核结果" class="same_line">
        <el-radio-group v-model="checkForm.checkResult">
          <el-radio :value="true" size="small">同意</el-radio>
          <el-radio :value="false" size="small">驳回</el-radio>
        </el-radio-group>
      </el-form-item>

      <!--驳回备注-->
      <el-form-item label="驳回备注">
        <el-input
          v-model.trim="checkForm.remark"
          :disabled="checkForm.checkResult"
          placeholder="请输入驳回备注"
          type="textarea"
          maxlength="100"
          show-word-limit
          resize="both"
        />
      </el-form-item>
    </el-form>

    <template #footer>
      <h-button type="primary" is-modal @click="onConfirm">确定</h-button>
      <h-button is-modal @click="hideDialog">取消</h-button>
    </template>
  </h-dialog>
</template>

<style scoped lang="scss">
  :deep(.el-textarea__inner) {
    width: 100% !important;
    height: 100px !important;
  }
</style>
